package States 
{
	import nl.jorisdormans.phantom2D.ai.statemachines.State;
	import nl.jorisdormans.phantom2D.ai.statemachines.StateMachine;
	import nl.jorisdormans.phantom2D.core.Composite;
	import nl.jorisdormans.phantom2D.objects.GameObject;
	/**
	 * ...
	 * @author Sebastiaan
	 */
	public class LowGrav extends State
	{
		private var timer : Number;
		private var delay : Number;
		
		private var gravity : int;
		private var oldGrav : int;
		private var minGrav : uint = 200;
		private var maxGrav : uint = 350;
		
		public function LowGrav() 
		{
			gravity = Math.floor(Math.random() * (1 + maxGrav - minGrav) + minGrav);
			oldGrav = Player.getGravity();
		}
		
		override public function onActivate():void 
		{
			super.onActivate();
			this.timer = 4 + Math.random() * 8;
			this.delay = 1.0;
			Player.setGravity(gravity);
		}
		
		
		override public function update(elapsedTime:Number):void 
		{
			super.update(elapsedTime);
			
			if (timer > 0) 
			{
				if (delay <= 0)
				{
					delay = 1.0
				}
				
				delay -= elapsedTime;
				timer -= elapsedTime;
			}
			else
			{
				Player.setGravity(oldGrav);
				this.stateMachine.popState();
			}
		}
		
	}

}